import Pagination from "@/components/pagination";
import { Message } from "element-ui";
const easydate = require("@/untils/easydate");
export default {
  components: {
    Pagination
  },
  props: ["activeName"],
  data() {
    return {
      turnPageObj:{},
      checkApply: false,
      downLoadPg:false,
      downLoadHref:false,
      searchLoading: false,
      total: 10,
      agree: false,
      disagree: false,
      qryCourseByIdObj: {
        title: "", // 课程名称
        introduce: "", // 课程说明
        courseTime: "", // 时长
        openTime: "", // 日期
        updateTime: "", // 时间
        address: "", // 地点
        num: "", // 人数
        courseDepts: "", // 课程类别
        isOpen:'', // 是否公开
        isGood:'' // 是否推荐
      },
      username: "",
      title: "",
      courseDept: "",
      classId: "",
      tableData: [],
      Ahref:''
    };
  },
  mounted() {
    let params = {
      title: "",
      username: "",
      courseDept: "",
      page: 1,
      pageSize: 10
    };
    this.qryOverCoursePCResult(params);
  },
  methods: {
    uploadPg(id){
      let params = {
        id
      }
      this.$get('downZipForCourse',params).then(res => {
        if(res.success){
          this.downLoadHref = res.data;
          this.downLoadPg = true;
        }
      })
    },
    pageNum(prop){
      this.searchList(prop,10);
    },
    pageSizeNum(prop){
      this.searchList(1,prop);
    },
    initData(row, column) {
      return row.flag == 0 ? "不公开" : row.flag == 1 ? "公开" : "暂无";
    },
    initCourseDept(row, column) {
      return row.courseDept == 0 ? "部门课程" : row.flag == 1 ? "公司课程" : "暂无";
    },
    handleClose(done) {
      done();
    },
    searchList(page,pageSize) {
      let { title, username, courseDept } = this;
      let params = {
        title,
        username,
        courseDept,
        page,
        pageSize
      };
      this.searchLoading = true;
      this.qryOverCoursePCResult(params);
      this.turnPageObj = params;
    },
    applyClick(row) {
      console.log(row);
      let params = {
        id: row.id
      };
      this.classId = row.id;
      this.$get("qryCourseById", params, true).then(res => {
        if (res.success) {
          this.checkApply = true;
          for(var key in res.data){
            if(key == 'isOpen' || key == 'isGood'){
              if(res.data[key] == 0){
                res.data[key] = false;
              }else{
                res.data[key] = true;
              }
            }
            if(key == "openTime"){
              res.data.date = easydate(res.data[key]).format('yyyy年MM月dd日 HH:mm').split(' ')[0];
              res.data.time = easydate(res.data[key]).format('yyyy年MM月dd日 HH:mm').split(' ')[1];
            }
            if(key == 'courseDept'){
              if(res.data[key] == 1){
                res.data.courseDept = '公司课程'
              }else {
                res.data.courseDept = '部门课程'
              }
            }
          }
          this.qryCourseByIdObj = res.data;
        }
      });
    },
    apply(status) {
      let id = this.classId;
      let params = {
        courseId: id,
        teaStatus: status
      };
      if (status == 0) {
        this.disagree = true;
      } else {
        this.agree = true;
      }
      this.$get("approvalOverCourse", params).then(res => {
        if (res.success) {
          Message({
            message: "操作成功",
            type: "success",
            duration: 2000
          });
          if (status == 0) {
            this.disagree = false;
          } else {
            this.agree = false;
          }
          this.checkApply = false;
          this.searchList(1,10);
        }
      });
    },
    qryOverCoursePCResult(params) {
      this.$post("qryOverCoursePCResult", params).then(res => {
        if (res.success) {
          let isObjNull = JSON.stringify(res.data);
          if (isObjNull !== "{}") {
            this.tableData = res.data.coursePCBackList;
            this.total = res.data.totals;
            console.log(this.total);
          }
          this.searchLoading = false;
        }
      });
    }
  }
};